﻿CREATE PROCEDURE [acms].[Post_GetTopLevelBySiteId]
	@SiteId int,
	@SiteVersion datetime
	
AS
	declare @tmp datetime
	set @tmp = acms.GetPublishDate(@SiteId, @SiteVersion)
	
	if(@tmp is null and @SiteVersion is not null)
		return
	
	
	SELECT a.*, b.[ParentPath] as ParentPath, b.PublishDate as SiteVersion
	FROM [Post_View] a
		inner join PostPositions b on a.Id = b.PostId and isnull(b.PublishDate, '9999/12/31') = isnull(@tmp, '9999/12/31')
	WHERE a.SiteId = @SiteId
		and a.ParentGuid is null

RETURN 0;